package droid.engine;

import android.view.*;
import android.graphics.*;

public class GraphicsThread extends Thread {
	
	private SurfaceHolder surfaceHolder;
	private Panel panel;
	private boolean run = false;
	
	public GraphicsThread(SurfaceHolder surfaceHolder, Panel panel) {
		this.surfaceHolder = surfaceHolder;
		this.panel = panel;
	}
	
	public void setRunning(boolean run) {
		this.run = run;
	}
	
	@Override
	public void run() {
		Canvas c;
		while (run) {
			c = null;
			try {
				c = surfaceHolder.lockCanvas(null);
				synchronized (surfaceHolder) {
					panel.onDraw(c);
				}
			}
			catch (Exception e) {
				
			}
			finally {
				if (c != null)
					surfaceHolder.unlockCanvasAndPost(c);
			}
		}
	}
}
